package com.qiwx.pigeon.activity.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.andview.refreshview.XRefreshView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.qiwx.pigeon.R;
import com.qiwx.pigeon.Utils.DBSqlUtil;
import com.qiwx.pigeon.Utils.DateTimeUtils;
import com.qiwx.pigeon.Utils.MyToast;
import com.qiwx.pigeon.adapter.home.CageChangeAdapter;
import com.qiwx.pigeon.adapter.home.EliminateAdapter;
import com.qiwx.pigeon.adapter.home.RemindCheckEggAdapter;
import com.qiwx.pigeon.base.BaseActivity;
import com.qiwx.pigeon.data.db.SummaryEliminateModel;
import com.qiwx.pigeon.data.params.CageParam;
import com.qiwx.pigeon.data.vo.CageBeanVo;
import com.qiwx.pigeon.data.vo.CageRemindBean;
import com.qiwx.pigeon.data.vo.EliminateBean;
import com.qiwx.pigeon.data.vo.QueryCageBean;
import com.qiwx.pigeon.data.vo.WareHouseBean;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.widget.ArrowView;
import com.qiwx.pigeon.widget.itemderection.LineItemDecoration;

import org.angmarch.views.NiceSpinner;
import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-06 17:30
 * 淘汰种鸽
 **/
public class EliminateActivity extends BaseRemindActivity {
    List<EliminateBean> data = new ArrayList<>();
    CageParam cageParam = new CageParam();
    int current_pos = -1;

    @Override
    public void initAfterOnCreate() {
        cageParam.setPageSize(pageSize);
        initView();
        // xRefreshView.startRefresh();
    }

    @Override
    public void loadData(boolean isRefresh) {
        if (isRefresh) {
            pageNo = 1;
            data.clear();
        } else {
            pageNo++;
        }
        cageParam.setWh_id(wh_id);
        mPresenter.queryCageEliminateByPage(cageParam);
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        adapter = new EliminateAdapter(R.layout.adapter_remind_eliminate_list_item, data);
        return adapter;
    }

    @Override
    public int getSize() {
        return data.size();
    }

    @Override
    public int addListViewHead() {
        return R.layout.cage_remind_eliminate_headview;
    }

    @Override
    public void initView() {
        super.initView();
        titleReturn.changeArrowLeft();
        titleContent.setText("应淘汰种鸽列表");
        txtAmountName.setText("汰种鸽笼合计(个)：");

        if (adapter != null && adapter instanceof EliminateAdapter) {
            ((EliminateAdapter) adapter).setIPigeonPairInterface((pos, c_id, methodId) -> {
                addEliminate(pos, c_id, methodId);
            });
        }

    }

    //添加鸽笼到淘汰表里
    public void addEliminate(int pos, int c_id, int methoid) {
        if (methoid == 0) {//查看详情
            Intent go = new Intent(this, CageDetailActivity.class);
            go.putExtra("c_id", c_id);
            startActivity(go);
        } else {//淘汰
            current_pos = pos;
            mPresenter.updateCageEliminate(data.get(pos));
        }

    }

    @Override
    public void onQueryEliminateBeanSuccess(PageInfo<EliminateBean> bean) {
        if (bean != null && bean.getList() != null) {
            data.addAll(bean.getList());
        }
        super.onQueryEliminateBeanSuccess(bean);
    }

    @Override
    public void onUpdateCageStatusSuccess(int type) {
        if (current_pos >= 0) {
            data.remove(current_pos);
            adapter.notifyDataSetChanged();
            current_pos = -1;
            updateAmount(-1);

        }
    }

}
